package com.escool.dao;

import java.util.List;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.escool.model.TbMateria;
@Repository
public class MateriaDAOImpl implements MateriaDAO {
	
	@Autowired
	SessionFactory sessionFactory;

	@Override
	public void addMateria(TbMateria materia) {
		sessionFactory.getCurrentSession().save(materia);

	}

	@Override
	public void updateMateria(TbMateria materia) {
		sessionFactory.getCurrentSession().update(materia);

	}

	@Override
	public List<TbMateria> listMateria() {
		return sessionFactory.getCurrentSession().createQuery("from TbMateria").list();
	}

	@Override
	public void deleteMateria(Integer id) {
		TbMateria materia = (TbMateria) sessionFactory.getCurrentSession().load(TbMateria.class, id);
		if(materia != null){
			sessionFactory.getCurrentSession().delete(materia);
		}
	}

}
